package com.gzp.config;

import javax.jms.ConnectionFactory;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;

/**
 * 配置监听容器
 * 
 * @author Administrator
 *
 */
@Configuration
public class JmsContainerFactoryConfig {

	/**
	 * 队列的监听容器
	 * 
	 * @param connectionFactory
	 * @return
	 */
	@Bean
	public DefaultJmsListenerContainerFactory jmsQueueListenerContainerFactory(ConnectionFactory connectionFactory) {
		DefaultJmsListenerContainerFactory containerFactory = new DefaultJmsListenerContainerFactory();
		containerFactory.setConnectionFactory(connectionFactory);
		containerFactory.setPubSubDomain(false);// 设置对队列的监听
		return containerFactory;
	}

	/**
	 * 主题的监听容器
	 * 
	 * @param connectionFactory
	 * @return
	 */
	@Bean
	public DefaultJmsListenerContainerFactory jmsTopicListenerContainerFactory(ConnectionFactory connectionFactory) {
		DefaultJmsListenerContainerFactory containerFactory = new DefaultJmsListenerContainerFactory();
		containerFactory.setConnectionFactory(connectionFactory);
		containerFactory.setPubSubDomain(true);// 设置对主题的监听
		return containerFactory;
	}
}
